﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VTESCore;

namespace VTESGameLogicWindows
{
	public class GameFlowManager
	{
		private List<IPlayer> m_PlayersInGame;
		private int m_CurrentRound;

		private static GameFlowManager m_Inst;

		static GameFlowManager()
		{
			m_Inst = new GameFlowManager();
		}

		public static GameFlowManager Instance
		{
			get { return m_Inst; }
		}

		public void InitializeGameFlowManager(List<IPlayer> players_in_game)
		{
			m_PlayersInGame = players_in_game;
			m_CurrentRound = 1;
		}

		public void ExecuteGameFlow()
		{
			while ( m_PlayersInGame.Count > 1 )
			{
				foreach ( IPlayer player in m_PlayersInGame )
				{
					// DEBUG - THE PARAMS ARE ALL TEST VALUES, WILL NEED TO BE FILLED IN BY USER INPUT OR AI OR NETWORK COMPONENTS
					player.PerformUntapPhase();
					player.PerformMasterPhase(new LibraryCard());
					player.PerformMinionPhase( new Minion( new CryptCard() ), MinionActions.Bleed, new LibraryCard(), player as IVTESGameEntity);
					player.PerformInfluencePhase(4, player as IVTESGameEntity, player as IVTESGameEntity );
					player.PerformDiscardPhase( null );
				}

				// Oust dead players
				m_PlayersInGame.RemoveAll( delegate( IPlayer player ) { return !player.Alive; } );
				
				m_CurrentRound++;
			}
		}
	}
}
